using System;
using System.Text;
namespace ServiceStack.Messaging
{
	public class MessageHandlerStats : IMessageHandlerStats
	{
		public string Name
		{
			get;
			private set;
		}
		public DateTime? LastMessageProcessed
		{
			get;
			private set;
		}
		public int TotalMessagesProcessed
		{
			get;
			private set;
		}
		public int TotalMessagesFailed
		{
			get;
			private set;
		}
		public int TotalRetries
		{
			get;
			private set;
		}
		public int TotalNormalMessagesReceived
		{
			get;
			private set;
		}
		public int TotalPriorityMessagesReceived
		{
			get;
			private set;
		}
		public MessageHandlerStats(string name)
		{
			this.Name = name;
		}
		public MessageHandlerStats(string name, int totalMessagesProcessed, int totalMessagesFailed, int totalRetries, int totalNormalMessagesReceived, int totalPriorityMessagesReceived, DateTime? lastMessageProcessed)
		{
			this.Name = name;
			this.TotalMessagesProcessed = totalMessagesProcessed;
			this.TotalMessagesFailed = totalMessagesFailed;
			this.TotalRetries = totalRetries;
			this.TotalNormalMessagesReceived = totalNormalMessagesReceived;
			this.TotalPriorityMessagesReceived = totalPriorityMessagesReceived;
			this.LastMessageProcessed = lastMessageProcessed;
		}
		public virtual void Add(IMessageHandlerStats stats)
		{
			this.TotalMessagesProcessed += stats.TotalMessagesProcessed;
			this.TotalMessagesFailed += stats.TotalMessagesFailed;
			this.TotalRetries += stats.TotalRetries;
			this.TotalNormalMessagesReceived += stats.TotalNormalMessagesReceived;
			this.TotalPriorityMessagesReceived += stats.TotalPriorityMessagesReceived;
			if (this.LastMessageProcessed.get_HasValue())
			{
				DateTime? lastMessageProcessed = stats.LastMessageProcessed;
				DateTime? lastMessageProcessed2 = this.LastMessageProcessed;
				if (!(lastMessageProcessed.get_HasValue() & lastMessageProcessed2.get_HasValue()) || !(lastMessageProcessed.GetValueOrDefault() > lastMessageProcessed2.GetValueOrDefault()))
				{
					return;
				}
			}
			this.LastMessageProcessed = stats.LastMessageProcessed;
		}
		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder("Stats for " + this.Name);
			stringBuilder.AppendLine("\n---------------");
			stringBuilder.AppendFormat("\nTotalNormalMessagesReceived: {0}", new object[]
			{
				this.TotalNormalMessagesReceived
			});
			stringBuilder.AppendFormat("\nTotalPriorityMessagesReceived: {0}", new object[]
			{
				this.TotalPriorityMessagesReceived
			});
			stringBuilder.AppendFormat("\nTotalProcessed: {0}", new object[]
			{
				this.TotalMessagesProcessed
			});
			stringBuilder.AppendFormat("\nTotalRetries: {0}", new object[]
			{
				this.TotalRetries
			});
			stringBuilder.AppendFormat("\nTotalFailed: {0}", new object[]
			{
				this.TotalMessagesFailed
			});
			stringBuilder.AppendFormat("\nLastMessageProcessed: {0}", new object[]
			{
				this.LastMessageProcessed.get_HasValue() ? this.LastMessageProcessed.get_Value().ToString() : ""
			});
			return stringBuilder.ToString();
		}
	}
}
